<script lang="ts" setup>
import {computed,ref} from "vue";
import type {Ref} from "vue";
import axios from "axios";
import  type { AxiosResponse } from "axios";

// 轮播图的数据
interface IBanner{
  alt: string,
  bannerid:string,
  flag: boolean,
  img: string,
  link: string
}

// 全部数据
let banners:Ref<Array<IBanner>> = ref<Array<IBanner>>([]);


axios({
  url:"http://121.89.205.189:3001/admin/banner/list",
  headers:{
    "token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbm5hbWUiOiJhZG1pbiIsImlhdCI6MTY2NjE1MDM1MiwiZXhwIjoxNjY2MTc5MTUyfQ.4d1cTqz0TlWxM_66DIfvI45pmtQbVFI6Bx6aivj3-Cg"
  }
}).then((res:AxiosResponse)=>{  
  if(res.data.code==="200"){
    console.log("res.data",res.data);
    banners.value = res.data.data;
  }
})


// 分页相关：
// 1)、每页五条数据。
let pageSize = ref(5);
// 2)、当前页码：
let currentPage = ref(1);

// 当前页的数据：使用计算属性，当页码发生变化，会重新获取当前页的数据
let list = computed(()=>banners.value.slice((currentPage.value-1)*pageSize.value,currentPage.value*pageSize.value))


</script>
<template>
  <div class="about">
    <h1>轮播图页面</h1>
    <el-table :data="list" style="width: 100%">
      <el-table-column prop="alt" label="图片提示" width="180" />
      <el-table-column prop="bannerid" label="图片编号" width="180" />
      <el-table-column label="是否应用" >
        <template #default="scope">
          <el-switch v-model="scope.row.flag" />
        </template>
      </el-table-column>

      <el-table-column label="图片地址" >
        <template #default="scope">
          <img :src="scope.row.img" style="width: 100px;height: 60px;" />        
      </template>
      </el-table-column>
      <el-table-column prop="link" label="跳转地址" />
    </el-table>
    <el-pagination v-model:page-size="pageSize" v-model:current-page="currentPage" background layout="prev, pager, next" :total="banners.length" />
  </div>
</template>

<style>

</style>
